//
//  BuyView.m
//  BigJoy
//
//  Created by Rowling on 2017/7/13.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "BuyView.h"
#import "MerchantBuyView.h"

@interface BuyView()
@property (nonatomic,strong)MerchantBuyView * buyview;
@end

@implementation BuyView

-(MerchantBuyView *)buyview {
    if (_buyview == nil) {
        _buyview = [MerchantBuyView fastLogin];
    }
    return _buyview;
}

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUI];
    }
    return self;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismims];
}

-(void)setUI {
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.buyview];
    self.buyview.frame = CGRectMake(0, SCREEN_HEIGHT - self.buyview.allHeight, SCREEN_WIDTH, self.buyview.allHeight);
}
-(void)animationShowWithView:(UIView *)view {
    [view addSubview:self];
    [self doAnimation];
}

-(void)dismims {
    [UIView animateWithDuration:0.3 animations:^{
        self.buyview.y = SCREEN_HEIGHT;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

-(void)doAnimation {
    CGFloat y = self.buyview.y;
    self.buyview.y = SCREEN_HEIGHT;
    [UIView animateWithDuration:0.3 animations:^{
        self.buyview.y = y;
    } completion:^(BOOL finished) {
        [self addbur];
    }];
}

-(void)addbur {
    // 加入毛玻璃效果
    UIBlurEffect * blurE = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
    UIVisualEffectView * blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurE];
    blurEffectView.frame = [UIScreen mainScreen].bounds;
    blurEffectView.alpha = 0.95;
    [self insertSubview:blurEffectView atIndex:0];
}
-(void)dealloc {
    NSLog(@"buyViewDealloc");
}

@end
